package com.ruoyi.project.projectCategory.service.impl;

import java.util.List;
import java.util.ArrayList;
import com.ruoyi.common.core.domain.Ztree;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.projectCategory.mapper.ProjectCategoryMapper;
import com.ruoyi.project.projectCategory.domain.ProjectCategory;
import com.ruoyi.project.projectCategory.service.IProjectCategoryService;
import com.ruoyi.common.core.text.Convert;

/**
 * projectCategoryService业务层处理
 *
 * @author xzshan
 * @date 2020-05-26
 */
@Service
public class ProjectCategoryServiceImpl implements IProjectCategoryService
{
    @Autowired
    private ProjectCategoryMapper projectCategoryMapper;

    /**
     * 查询projectCategory
     *
     * @param id projectCategoryID
     * @return projectCategory
     */
    @Override
    public ProjectCategory selectProjectCategoryById(Long id)
    {
        return projectCategoryMapper.selectProjectCategoryById(id);
    }

    /**
     * 查询projectCategory列表
     *
     * @param projectCategory projectCategory
     * @return projectCategory
     */
    @Override
    public List<ProjectCategory> selectProjectCategoryList(ProjectCategory projectCategory)
    {
        return projectCategoryMapper.selectProjectCategoryList(projectCategory);
    }

    /**
     * 新增projectCategory
     *
     * @param projectCategory projectCategory
     * @return 结果
     */
    @Override
    public int insertProjectCategory(ProjectCategory projectCategory)
    {
        return projectCategoryMapper.insertProjectCategory(projectCategory);
    }

    /**
     * 修改projectCategory
     *
     * @param projectCategory projectCategory
     * @return 结果
     */
    @Override
    public int updateProjectCategory(ProjectCategory projectCategory)
    {
        return projectCategoryMapper.updateProjectCategory(projectCategory);
    }

    /**
     * 删除projectCategory对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteProjectCategoryByIds(String ids)
    {
        return projectCategoryMapper.deleteProjectCategoryByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除projectCategory信息
     *
     * @param id projectCategoryID
     * @return 结果
     */
    @Override
    public int deleteProjectCategoryById(Long id)
    {
        return projectCategoryMapper.deleteProjectCategoryById(id);
    }

    /**
     * 查询projectCategory树列表
     *
     * @return 所有projectCategory信息
     */
    @Override
    public List<Ztree> selectProjectCategoryTree()
    {
        List<ProjectCategory> projectCategoryList = projectCategoryMapper.selectProjectCategoryList(new ProjectCategory());
        List<Ztree> ztrees = new ArrayList<Ztree>();
        for (ProjectCategory projectCategory : projectCategoryList)
        {
            Ztree ztree = new Ztree();
            ztree.setId(projectCategory.getId());
            ztree.setpId(projectCategory.getPid());
            ztree.setName(projectCategory.getName());
            ztree.setTitle(projectCategory.getName());
            ztrees.add(ztree);
        }
        return ztrees;
    }
}
